package com.yingpai.fitness.dvp_2_0.main.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

/**
=================================================
*作者: 国斌
*邮箱: remebermelula@aliyun.com
*时间: 2018/4/9
*类名:  ParentRecyclerView .java
*版本: V 1.0
*描述:自定义RecyclerView    这是一个父级控件   里面可以嵌套RecyclerView
 *
 * 并且对横向的RecyclerView事件分发做了处理   可以上下流畅的滑动  也可左右滑动
===============================================
*/


public class ParentRecyclerView extends RecyclerView {


    public ParentRecyclerView(Context context) {
        super(context);
    }

    public ParentRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ParentRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    /**
     * 重写   要求不允许拦截事件
     *
     * 主要解决内部嵌套横向滑动的RecyclerView 时  快速左右滑动时   上下滑动被拦截的问题
     * @param disallowIntercept
     */
    @Override
    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        //super.requestDisallowInterceptTouchEvent(disallowIntercept);

        //do nothing
    }

    @Override
    public boolean canScrollVertically(int direction) {
        // check if scrolling up
        if (direction < 1) {
            boolean original = super.canScrollVertically(direction);
            return !original && getChildAt(0) != null && getChildAt(0).getTop() < 0 || original;
        }
        return super.canScrollVertically(direction);

    }
}
